package com.example.homework_4_permission.controller;


import cn.dev33.satoken.annotation.SaIgnore;
import cn.dev33.satoken.stp.StpUtil;
import cn.dev33.satoken.util.SaResult;
import com.example.homework_4_permission.pojo.Result;
import com.example.homework_4_permission.pojo.User;
import com.example.homework_4_permission.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
@SaIgnore
@CrossOrigin
public class LoginController {

    @Autowired
    private UserService userService;

    @PostMapping("/login")
    public Result doLogin(@RequestBody User user){
        return userService.login(user);
    }

    @RequestMapping("/logout")
    public Result logout() {
        StpUtil.logout();
        return Result.ok("退出成功!");
    }
}
